import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _isFunction from "lodash/isFunction";
import { mapCustomize } from "../utils/customize";
/**
 * 如果 审批表单存在 则加载表单
 * 否则 返回 null
 * @param formCode
 * @return {Promise<null|*>}
 */

export function loadWorkflowApproveFormAsync(_x) {
  return _loadWorkflowApproveFormAsync.apply(this, arguments);
}

function _loadWorkflowApproveFormAsync() {
  _loadWorkflowApproveFormAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(formCode) {
    var layout, approveForm;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            if (!mapCustomize.has({
              module: 'cpaas-front-cwfp',
              feature: 'workflowApproveForm',
              key: formCode
            })) {
              _context.next = 7;
              break;
            }

            layout = mapCustomize.get({
              module: 'cpaas-front-cwfp',
              feature: 'workflowApproveForm',
              key: formCode
            });

            if (!_isFunction(layout && layout.component)) {
              _context.next = 7;
              break;
            }

            _context.next = 5;
            return layout.component();

          case 5:
            approveForm = _context.sent;
            return _context.abrupt("return", approveForm);

          case 7:
            return _context.abrupt("return", null);

          case 8:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _loadWorkflowApproveFormAsync.apply(this, arguments);
}

export function setWorkflowApproveForm(formConfig) {
  // TODO: 判断是否需要检查 重复设置的问题
  mapCustomize.set({
    module: 'cpaas-front-cwfp',
    feature: 'workflowApproveForm',
    key: formConfig.code,
    data: {
      component: formConfig.component
    }
  });
}